<template>
  <div style="text-align: left;margin-left: 30px">
    <div style="margin: 20px auto 20px">
      <el-page-header @back="goBack" content="新增模块"></el-page-header>
    </div>
    <div>
      <el-form inline :model="moduleInfo" label-width="80px" style="width: 600px" label-position="right">
        <el-form-item label="模块名称:">
          <el-input style="width: 400px" v-model="moduleInfo.module_name"></el-input>
        </el-form-item>
        <el-form-item label="所属项目:">
          <el-select style="width: 400px" v-model="moduleInfo.belong_project_id" filterable placeholder="请选择项目">
            <el-option v-for="item in projectInfo" :key="item.pk" :label="item.fields.project_name" :value="item.pk"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="测试人员:">
          <el-input style="width: 400px" v-model="moduleInfo.test_user"></el-input>
        </el-form-item>
        <el-form-item label="简要描述:">
          <el-input type="textarea" :rows="2" style="width: 400px" v-model="moduleInfo.simple_desc"></el-input>
        </el-form-item>
        <el-form-item label="其他信息:">
          <el-input type="textarea" :rows="2" style="width: 400px" v-model="moduleInfo.other_desc"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="moduleAdd()">提 交</el-button>
      </div>
    </div>
  </div>
</template>

<script>

export default {
    name: "modelAdd",
    data() {
        return {
            projectId: '', //页面初始时，url中传递过来的projectId
            projectInfo: [],
            moduleInfo: {
                module_name: "",
                belong_project_id: "",
                test_user: "",
                simple_desc: "",
                other_desc: "",
            },
        }
    },
    methods: {
        getProjectInfo() {
            this.projectId = this.$route.query.projectId;
            this.$axios.get("/api/projectList/", {params: {'projectId': this.projectId, 'type': 'moduleAdd'}})
                .then(res => {
                    console.log('获取项目：');
                    console.log(res.data.projectList);
                    this.projectInfo = res.data.projectList;
                })
        },
        moduleAdd() {
            this.$axios.post("/api/moduleAdd/", {"moduleInfo": this.moduleInfo})
                .then(res => {
                    if (res.data.msgCode === '1') {
                        console.log("新增模块成功");
                        this.$router.back()
                    }
                })
                .catch(error => {
                    console.log("新增模块失败")
                })
        },
        // 页面返回
        goBack() {
            console.log('go back');
            this.$router.back();
        },
    },
    created() {
        this.getProjectInfo();
    }
}
</script>

<style scoped>

</style>
